package cn.gzjp.modules.logis.service;

import java.util.List;

import cn.gzjp.modules.logis.entity.NewsType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;

import cn.gzjp.common.persistence.Page;
import cn.gzjp.common.service.CrudService;
import cn.gzjp.modules.logis.dao.NewsTypeDao;

/**
 * 新闻类型Service
 * @author zengcp
 * @version 2017-08-17
 */
@Service
@Transactional(readOnly = true)
public class NewsTypeService extends CrudService<NewsTypeDao, NewsType> {

	public NewsType get(String id) {
		return super.get(id);
	}
	
	public List<NewsType> findList(NewsType businessType) {
		return super.findList(businessType);
	}
	
	public Page<NewsType> findPage(Page<NewsType> page, NewsType businessType) {
		return super.findPage(page, businessType);
	}
	
	@Transactional(readOnly = false)
	public void save(NewsType businessType) {
		super.save(businessType);
	}
	
	@Transactional(readOnly = false)
	public void delete(NewsType businessType) {
		super.deleteByLogic(businessType);
	}
	
	public List<NewsType> findTreeList() {
		NewsType search = new NewsType();
		search.setParent(new NewsType("0"));
		List<NewsType> roots = findList(search);
		List<NewsType> results = Lists.newArrayList();
		for(NewsType type:roots){
			search.setParent(new NewsType(type.getId()));
			type.setChildren(findList(search));
			results.add(type);
		}
		return results;
	}
	
}